package com.coder520.sync_learning.demo;

import java.util.concurrent.TimeUnit;

public class Interruted {
	public static void main(String[] args) throws InterruptedException {
//		sleepThread不停的尝试睡眠
		Thread sleep=new Thread(new SleepRunner(),"SleepRunner");
		sleep.setDaemon(true);
//		busyThread不停运行
		Thread busyThread=new Thread(new BusyRunner(),"BusyRunner");
		busyThread.setDaemon(true);
		
		sleep.start();
		busyThread.start();
		
		TimeUnit.SECONDS.sleep(6);
		sleep.interrupt();
		busyThread.interrupt();
		 System.out.println("SleepThread interrupted is " + sleep.isInterrupted());
	        System.out.println("BusyThread interrupted is " + busyThread.isInterrupted());
	        // 防止sleepThread和busyThread立刻退出        
		 SleepUtils.second(2);
	}
	
	static class SleepRunner implements Runnable{

		@Override
		public void run() {
			// TODO Auto-generated method stub
			while (true) {
				SleepUtils.second(10);
			}
		}
	}
	
	static class BusyRunner implements Runnable{

		@Override
		public void run() {
			// TODO Auto-generated method stub
			while (true) {
				
			}
		}
		
	}
}
